From 01d0370a524dad01148a6088306d8eb49fdf913d Mon Sep 17 00:00:00 2001 From: "shand@ubuntu.eng.hq.xensource.com" Date: Fri, 2 Sep 2005 17:36:29 -0800 Subject: [PATCH] Enable 'live' migration from a tools pov; prior to this the 'live' flag was being ignored by xend/xc_linux_save. Signed-off-by: Steven Hand --- tools/libxc/xc_linux_save.c | 51 ++++++++++++++++++------- tools/libxc/xenguest.h | 21 +++++----- tools/python/xen/xend/XendCheckpoint.py | 9 ++++- tools/python/xen/xend/XendDomain.py | 5 ++- tools/xcutils/xc_save.c | 11 ++++-- 5 files changed, 65 insertions(+), 32 deletions(-) diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index a4ae0c8db7..d0797b15ae 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -21,6 +21,24 @@ #define MAX_MBIT_RATE 500 + +/* +** Default values for important tuning parameters. Can override by passing +** non-zero replacement values to xc_linux_save(). +** +** XXX SMH: should consider if want to be able to override MAX_MBIT_RATE too. +** +*/ +#define DEF_MAX_ITERS 29 /* limit us to 30 times round loop */ +#define DEF_MAX_FACTOR 3 /* never send more than 3x nr_pfns */ + + + +/* Flags to control behaviour of xc_linux_save */ +#define XCFLAGS_LIVE 1 +#define XCFLAGS_DEBUG 2 + + #define DEBUG 0 #if 1 @@ -320,18 +338,18 @@ static int suspend_and_state(int xc_handle, int io_fd, int dom, xc_dominfo_t *info, vcpu_guest_context_t *ctxt) { - int i=0; + int i = 0; char ans[30]; printf("suspend\n"); fflush(stdout); if (fgets(ans, sizeof(ans), stdin) == NULL) { - ERR("failed reading suspend reply"); - return -1; + ERR("failed reading suspend reply"); + return -1; } if (strncmp(ans, "done\n", 5)) { - ERR("suspend reply incorrect: %s", ans); - return -1; + ERR("suspend reply incorrect: %s", ans); + return -1; } retry: @@ -377,20 +395,17 @@ retry: return -1; } -int xc_linux_save(int xc_handle, int io_fd, u32 dom) +int xc_linux_save(int xc_handle, int io_fd, u32 dom, u32 max_iters, + u32 max_factor, u32 flags) { xc_dominfo_t info; int rc = 1, i, j, k, last_iter, iter = 0; unsigned long mfn; - int live = 0; // (ioctxt->flags & XCFLAGS_LIVE); - int debug = 0; // (ioctxt->flags & XCFLAGS_DEBUG); + int live = (flags & XCFLAGS_LIVE); + int debug = (flags & XCFLAGS_DEBUG); int sent_last_iter, skip_this_iter; - /* Important tuning parameters */ - int max_iters = 29; /* limit us to 30 times round loop */ - int max_factor = 3; /* never send more than 3x nr_pfns */ - /* The new domain's shared-info frame number. */ unsigned long shared_info_frame; @@ -442,8 +457,16 @@ int xc_linux_save(int xc_handle, int io_fd, u32 dom) MBIT_RATE = START_MBIT_RATE; - DPRINTF("xc_linux_save start %d\n", dom); - + + /* If no explicit control parameters given, use defaults */ + if(!max_iters) + max_iters = DEF_MAX_ITERS; + if(!max_factor) + max_factor = DEF_MAX_FACTOR; + + + DPRINTF("xc_linux_save start DOM%u live=%s\n", dom, live?"true":"false"); + if (mlock(&ctxt, sizeof(ctxt))) { ERR("Unable to mlock ctxt"); return 1; diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h index 971ddf6de5..10467e8476 100644 --- a/tools/libxc/xenguest.h +++ b/tools/libxc/xenguest.h @@ -6,13 +6,12 @@ * Copyright (c) 2003-2004, K A Fraser. */ -#ifndef XENBUILD_H -#define XENBUILD_H +#ifndef XENGUEST_H +#define XENGUEST_H + +#define XCFLAGS_LIVE 1 +#define XCFLAGS_DEBUG 2 -#define XCFLAGS_VERBOSE 1 -#define XCFLAGS_LIVE 2 -#define XCFLAGS_DEBUG 4 -#define XCFLAGS_CONFIGURE 8 /** * This function will save a domain running Linux. @@ -22,7 +21,8 @@ * @parm dom the id of the domain * @return 0 on success, -1 on failure */ -int xc_linux_save(int xc_handle, int fd, uint32_t dom); +int xc_linux_save(int xc_handle, int fd, uint32_t dom, uint32_t max_iters, + uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */); /** * This function will restore a saved domain running Linux. @@ -35,8 +35,9 @@ int xc_linux_save(int xc_handle, int fd, uint32_t dom); * @parm store_mfn returned with the mfn of the store page * @return 0 on success, -1 on failure */ -int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, unsigned long nr_pfns, - unsigned int store_evtchn, unsigned long *store_mfn); +int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, + unsigned long nr_pfns, unsigned int store_evtchn, + unsigned long *store_mfn); int xc_linux_build(int xc_handle, uint32_t domid, @@ -65,4 +66,4 @@ int xc_vmx_build(int xc_handle, unsigned int store_evtchn, unsigned long *store_mfn); -#endif +#endif // XENGUEST_H diff --git a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py index 1fdcda04e2..0157c25cd5 100644 --- a/tools/python/xen/xend/XendCheckpoint.py +++ b/tools/python/xen/xend/XendCheckpoint.py @@ -34,7 +34,7 @@ def read_exact(fd, size, errmsg): raise XendError(errmsg) return buf -def save(xd, fd, dominfo): +def save(xd, fd, dominfo, live): write_exact(fd, SIGNATURE, "could not write guest state file: signature") config = sxp.to_string(dominfo.sxpr()) @@ -42,8 +42,13 @@ def save(xd, fd, dominfo): "could not write guest state file: config len") write_exact(fd, config, "could not write guest state file: config") + # xc_save takes three customization parameters: maxit, max_f, and flags + # the last controls whether or not save is 'live', while the first two + # further customize behaviour when 'live' save is enabled. Passing "0" + # simply uses the defaults compiled into libxenguest; see the comments + # and/or code in xc_linux_save() for more information. cmd = [PATH_XC_SAVE, str(xc.handle()), str(fd), - str(dominfo.id)] + str(dominfo.id), "0", "0", str(live) ] log.info("[xc_save] " + join(cmd)) child = xPopen3(cmd, True, -1, [fd, xc.handle()]) diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 080fc4ae8b..3b32b707cb 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -542,7 +542,7 @@ class XendDomain: dominfo.name = "tmp-" + dominfo.name try: - XendCheckpoint.save(self, sock.fileno(), dominfo) + XendCheckpoint.save(self, sock.fileno(), dominfo, live) except: if dst == "localhost": dominfo.name = string.replace(dominfo.name, "tmp-", "", 1) @@ -563,7 +563,8 @@ class XendDomain: fd = os.open(dst, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) - return XendCheckpoint.save(self, fd, dominfo) + # For now we don't support 'live checkpoint' + return XendCheckpoint.save(self, fd, dominfo, False) except OSError, ex: raise XendError("can't write guest state file %s: %s" % diff --git a/tools/xcutils/xc_save.c b/tools/xcutils/xc_save.c index 37c0bf17d4..eac8d1ad2b 100644 --- a/tools/xcutils/xc_save.c +++ b/tools/xcutils/xc_save.c @@ -17,14 +17,17 @@ int main(int argc, char **argv) { - unsigned int xc_fd, io_fd, domid; + unsigned int xc_fd, io_fd, domid, maxit, max_f, flags; - if (argc != 4) - errx(1, "usage: %s xcfd iofd domid", argv[0]); + if (argc != 7) + errx(1, "usage: %s xcfd iofd domid maxit maxf flags", argv[0]); xc_fd = atoi(argv[1]); io_fd = atoi(argv[2]); domid = atoi(argv[3]); + maxit = atoi(argv[4]); + max_f = atoi(argv[5]); + flags = atoi(argv[6]); - return xc_linux_save(xc_fd, io_fd, domid); + return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags); } -- 2.30.2